﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using System.Data;
using System.Text;
using Maticsoft.DBUtility;
using Utils;
using System.Collections.Specialized;
using Maticsoft.Model;

public partial class WebPage_ajaxPage_Ajax_user : SystemBBasePage 
{
    // Fields

    private Maticsoft.BLL. UserInfo userInfos = new Maticsoft.BLL.UserInfo();

    // Methods
    private void inputMoney(int uid, decimal money)
    {
        UserInfo model = new UserInfo();
        model = this.userInfos.GetModel(uid);
        model.Money += money;
        this.userInfos.Update(model);
        Maticsoft.BLL.Flow flow = new Maticsoft.BLL.Flow();
        Flow flow2 = new Flow();
        flow2.Action = "store";
        flow2.Admin_id = base.ASUser.Id;
        flow2.Create_time = DateTime.Now;
        flow2.Detail_id = "0";
        flow2.Direction = "income";
        flow2.Money = money;
        flow2.User_id = uid;
        flow.Add(flow2);
        if (money.ToString().IndexOf('-') >= 0)
        {
            money = decimal.Parse(money.ToString().Substring(1));
            base.SetSuccess(string.Concat(new object[] { model.Username, "减去金额成功！减去金额为", base.ASSystemArr["Currency"], money }));
        }
        else
        {
            base.SetSuccess(string.Concat(new object[] { model.Username, "充值成功！充值金额为", base.ASSystemArr["Currency"], money }));
        }
        base.Response.Redirect(this.Page.Request.UrlReferrer.AbsoluteUri);
        base.Response.End();
    }

    public bool IsNumeric(string str)
    {
        if ((str == null) || (str.Length == 0))
        {
            return false;
        }
        if (str.IndexOf('-') >= 0)
        {
            str = str.Substring(1);
        }
        byte[] bytes = new ASCIIEncoding().GetBytes(str);
        foreach (byte num in bytes)
        {
            if ((num < 0x30) || (num > 0x39))
            {
                return false;
            }
        }
        return true;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (base.Request.QueryString["Id"] != null)
        {
            this.setContent(int.Parse(base.Request.QueryString["Id"].ToString()));
        }
        if (base.Request.HttpMethod == "POST")
        {
            string str = base.Request["inputmoeny"].ToString();
            if (!this.IsNumeric(str))
            {
                try
                {
                    decimal num = Convert.ToDecimal(str);
                }
                catch
                {
                    this.SetError("充值失败！输入的不是数值");
                    base.Response.Redirect(this.Page.Request.UrlReferrer.AbsoluteUri);
                    base.Response.End();
                    return;
                }
            }
            decimal @decimal = Helper.GetDecimal(base.Request["inputmoeny"], 0M);
            this.inputMoney(int.Parse(this.user_Id.Value), Convert.ToDecimal(@decimal));
        }
    }

    private void setContent(int id)
    {
       Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        UserInfo model = new UserInfo();
        Maticsoft.BLL.Flow flow = new Maticsoft.BLL.Flow();
        model = info.GetModel(id);
        this.user_Id.Value = model.Id.ToString();
        this.user_email.InnerText = model.Email;
        this.user_username.InnerText = model.Username;
        this.user_realname.InnerText = model.Realname;
        this.user_mobile.InnerText = model.Mobile;
        this.user_zipcode.InnerText = model.Zipcode;
        this.user_address.InnerText = model.Address;
        this.user_ip.InnerText = model.IP;
        this.user_money.InnerText = model.Money.ToString();
        this.user_score.InnerText = model.Score.ToString();
        this.user_constcount.InnerText = flow.GetModelList("User_id=" + id + " and Direction='expense'").Count.ToString();
        decimal num = 0M;
        foreach (Flow flow2 in flow.GetModelList("User_id=" + id + " and Direction='expense'"))
        {
            num += Convert.ToDecimal(flow2.Money);
        }
        this.user_cost.InnerText = num.ToString();
    }

}